<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Live\Controller;
use Think\Controller;
class PayController extends Controller {
	
//	public function index(){
//			$geturl = I('post.url');
//			$getmoney = I('post.money');
//			$money = $getmoney * C('MONEYMATRIXING'); //金额换算
//			if($money<1){
//				echo "<script>alert('最小金额为1.00RMB');</script>";
//				die;
//			}
//			$liveid = I('post.liveid');
//			$bodystr = I('post.bodystr');
//		    $userinfo = $_COOKIE['user_userinfo'];
//			//判断用户是否与微信同步登陆
//			if(empty($userinfo)){
//				//echo 0;
//				header("Location:".C('LOGINADDRES')."?url=".$geturl);
//			}else{
//				$payinfo = array();
//				$payinfo['geturl'] = $geturl;
//				$payinfo['liveid'] = $liveid;
//				$payinfo['bodystr'] = $bodystr;
//				$payinfo['userinfo'] = $userinfo;
//				$payinfo['money'] = $money;
//
//				//支付开始
//				define('APPID',C('APPID'));
//				define('MCHID', C('MCHID'));
//				define('KEY', C('KEY'));
//				define('APPSECRET', C('APPSECRET'));
//				vendor('Pay.JSAPI');
//				$tools = new \JsApiPay();
//				$Out_trade_no=date('YHis').rand(100,1000);
//				//$Total_fee='测试';
//				$payinfo['cordernumber'] = $Out_trade_no;
//				$input = new \WxPayUnifiedOrder();
//				$input->SetBody($payinfo['bodystr']);
//				$input->SetOut_trade_no($payinfo['cordernumber']);
//				$input->SetTotal_fee($payinfo['money']); //金额
//				$input->SetNotify_url(C('WEBDOMAIN')."/Live/Pay/notify/"); //支付成功后的回调地址
//				$input->SetTrade_type("JSAPI");
//				$input->SetOpenid($payinfo['userinfo']);
//				$order = \WxPayApi::unifiedOrder($input);
//				$this->assign('payinfo',$payinfo);
//				$this->assign('jsApiParameters',$tools->GetJsApiParameters($order));
//
//				$this->display();
//			}
//
//	}
//
//	public function notify(){
//		//支付成功，操作API进行交易记录
//		echo 1;
//	}

	public function paysuccess(){
		//支付成功，操作API进行交易记录
//		$apiurl = "http://api.ximalaya.com/albums/browse";
//		$fieldarray = array(
//				'geturl'			=>	I('post.geturl','',htmlspecialchars),
//				'liveid'			=>	I('post.liveid','',htmlspecialchars),
//				'bodystr'			=>	I('post.bodystr','',htmlspecialchars),
//				'userinfo'			=>	I('post.userinfo','',htmlspecialchars),
//				'cordernumber'		=>	I('post.cordernumber','',htmlspecialchars),
//				'money'				=>	I('post.money','',htmlspecialchars),
//				'protype'			=>	I('post.protype','',htmlspecialchars),
//		);
//		$result = $this->get_info_content($apiurl, $fieldarray);
//		if($result){
//			echo 1;	//成功
//		}else{
//			echo 0;	//失败
//		}
		$userinfo = $_COOKIE['user_userinfo'];
		$liveid				=	I('post.liveid');
		$bodystr			=	I('post.bodystr')."（华人钻充值）";
		$cordernumber		=	I('post.cordernumber');
		$money				=	I('post.money');
		$protype			=	I('post.protype');
		$moneyconsume = D(C('TABLE_MONEYCONSUME'));
		$moneyconsume->user_token		=	$userinfo;
		$moneyconsume->live_id			=	$liveid;
		$moneyconsume->consume_moneynum	=	$money / C('MONEYMATRIXING');
		$moneyconsume->consume_remark	=	$bodystr;
		$moneyconsume->cordernumber		=	$cordernumber;
		$moneyconsume->protype			=	$protype;
		$moneyconsume->consume_time		=	date("Y-m-d H:i:m");
		$result = $moneyconsume->add();
		if($result){
			$m = $money*C('DRILLSCALE');
			$r = request_get(C('APIADDRES1')."/addscore?token=".$userinfo."&score=".$m."&msg=".urlencode($bodystr));
			if($r['ret']==1){
				if($r['data']['msg']=='ok'){
					echo $m;	//成功
				}
			}
		}else{
			echo 0;	//失败
		}

	}

	protected function get_info_content($apiurl,$fieldarray){
		$str = null;
		foreach ($fieldarray as $key=>$v){
			$str .= $key.'='.$v.'&';
		}
		$apiurl = $apiurl."?".rtrim($str,'&');
		$res = request_post($apiurl, $fieldarray);
		return json_decode($res,true);
	}

	

}
?>